home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Multimedia / Movie3.0 / Source / xanim / unpacker.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-02  |  2.2 KB  |  76 lines

  1.  
  2. /*----------------------------------------------------------------------*
  3.  * unpacker.c Convert data from "cmpByteRun1" run compression. 11/15/85
  4.  *
  5.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  6.  * This software is in the public domain.
  7.  *
  8.  *    control bytes:
  9.  *     [0..127]   : followed by n+1 bytes of data.
  10.  *     [-1..-127] : followed by byte to be repeated (-n)+1 times.
  11.  *     -128       : NOOP.
  12.  *
  13.  * This version for the Commodore-Amiga computer.
  14.  * Modified for use with Unix
  15.  *----------------------------------------------------------------------*/
  16. #include <stdio.h>
  17. #define LONG int
  18. #define ULONG unsigned int
  19. #define BYTE char
  20. #define UBYTE unsigned char
  21. #define SHORT short
  22. #define USHORT unsigned short
  23. #define WORD short int
  24. #define UWORD unsigned short int
  25.  
  26. #define TRUE 1
  27. #define FALSE 0
  28.  
  29.  
  30.  
  31. /*----------- UnPackRow ------------------------------------------------*/
  32.  
  33. #define UGetByte()    (*source++)
  34. #define UPutByte(c)    (*dest++ = (c))
  35.  
  36. /* Given POINTERS to POINTER variables, unpacks one row, updating the source
  37.  * and destination pointers until it produces dstBytes bytes. */
  38.  
  39. LONG UnPackRow(pSource, pDest, srcBytes0, dstBytes0)
  40. BYTE  **pSource, **pDest;  LONG *srcBytes0, *dstBytes0; 
  41. {
  42.     register BYTE *source = *pSource; 
  43.     register BYTE *dest   = *pDest;
  44.     register LONG n;
  45.     register BYTE c;
  46.     register LONG srcBytes = *srcBytes0, dstBytes = *dstBytes0;
  47.     LONG error = TRUE;    /* assume error until we make it through the loop */
  48.  
  49.     while( dstBytes > 0 )  {
  50.     if ( (srcBytes -= 1) < 0 )  {error=1; goto ErrorExit;}
  51.         n = UGetByte() & 0xff;
  52.  
  53.         if (!(n & 0x80)) {
  54.         n += 1;
  55.         if ( (srcBytes -= n) < 0 )  {error=2; goto ErrorExit;}
  56.         if ( (dstBytes -= n) < 0 )  {error=3; goto ErrorExit;}
  57.         do {  UPutByte(UGetByte());  } while (--n > 0);
  58.         }
  59.  
  60.         else if (n != 0x80) {
  61.         n = (256-n) + 1;
  62.         if ( (srcBytes -= 1) < 0 )  {error=4; goto ErrorExit;}
  63.         if ( (dstBytes -= n) < 0 )  {error=5; goto ErrorExit;}
  64.         c = UGetByte();
  65.         do {  UPutByte(c);  } while (--n > 0);
  66.         }
  67.     }
  68.     error = FALSE;    /* success! */
  69.  
  70.   ErrorExit:
  71.     *pSource = source;  *pDest = dest; 
  72.     *srcBytes0 = srcBytes; *dstBytes0 = dstBytes;
  73.     return(error);
  74.     }
  75.  
  76.